	var user_req_id = null;
	var score_req_id = null;
	
	function setUID(uid){
		user_req_id = uid;
	}
	
	function getUID(){
		return user_req_id;
	}
	
	function setScoreId(sid){
		score_req_id = sid;
	}
	
	function getScoreId(){
		return score_req_id;
	}
	
	function initAspDiv(param){
		if (param == "infor"){
			initInforDiv();
		}
		else if (param == "state"){
			initStateDiv();
		}
		else if (param == "score"){
			initScoreDiv();
		}
	}
	
	// profile information 
	function initInforDiv(){
		if(!RDC.gui.exist("year")){
			return;
		}
			
		RDC.gui.hide("basicInfoEdit");	
		RDC.gui.hide("contactEdit");	
		RDC.gui.hide("studentEdit");
		RDC.gui.hide("businessEdit");		
		
		var curDate = new Date();
		var maxYear = curDate.getFullYear();
		var ySel = $("year");
		ySel.options.length = 0;		
		for(i = maxYear; i >= 1920; i-=1){
			var opt = new Option();
			opt.value = i;
			opt.text = i;
			ySel.options.add(opt);
		}		
		
		var mSel = $("month");
		mSel.options.length = 0;
		for(i = 1;i <= 12; i+=1) {
			opt = new Option();
			opt.value = i;
			opt.text = i;
			mSel.options.add(opt);
		}	
		
		setDays();
	
		fillYears("ststartdate", maxYear);
		fillYears("stenddate", maxYear);
		
		fillYears("crstartdate", maxYear);
		fillYears("crenddate", maxYear);
	}
	
		
	function setDays(){ 
		var slYear = $("year");		
		var vYear = parseInt(slYear.options[slYear.selectedIndex].text);
		var slMonth = $("month");
		var vMonth = parseInt(slMonth.options[slMonth.selectedIndex].text);
		var nDay = new Date(vYear,vMonth,0);
		var max = nDay.getDate();
		var day = $("day");
		day.length = 0;
		for(i = 0; i < max; i+=1){
			day.options[day.length++].value = day.length;
			day.options[day.length-1].text= day.length;
		}
 	}
 	 	
	function fillYears(yid, maxYear){
		var yr = $(yid);
		yr.options.length = 0;
		opt = new Option();
		opt.value = "请选择";
		opt.text = "请选择";
		opt.selected = true;
		yr.options.add(opt);
		for(i = maxYear; i >= 1920; i-=1){
			opt = new Option();
			opt.value = i;
			opt.text = i;
			yr.options.add(opt);
		}
	}
	
	// hide the "h" and show "s"
	function showBlock(h, s){
		RDC.gui.hide(h);
		RDC.gui.display(s);
	}
			
	function editBasicInfo(){
		RDC.gui.hide("basicInfoMsg");	
		showBlock("basicInfoView", "basicInfoEdit");
		
		$("realName").value=$("myname").innerHTML;
		var birth = $("mybirth").innerHTML.split("-");
		if(birth.length == 3){
			$("birthYear").value=parseInt(birth[0]);
			$("birthMonth").value=parseInt(birth[1]);
			$("birthDay").value=parseInt(birth[2]);
		}
		$("loveType").value=$("mylovedesc").innerHTML;
		$("sex").value=$("mysexdesc").innerHTML;
		var val = $("mycountry").innerHTML;
		if(val !== "")
			$("country").value = val;
		val = $("mycity").innerHTML;
		if(val !== "")
			$("city").value = val;
		val = $("myprovince").innerHTML;
		if(val !== "")
			$("province").value = val;
		$("realName").focus();
		RDC.gui.enable("saveUser");
	}
	
	function saveBasicInfo(){
		var user = {id:$("aspirantId").value, realName:null, sex:null, mail:null, birthday:null, loveType:null, country: null, province: null, city: null};
		dwr.util.getValues(user);
		user.loveType = $("loveType").selectedIndex;		
		if($("sex").selectedIndex == 1){
			user.sex = 'm';
		}
		else {
			user.sex = 'f';
		}
		user.birthday = new Date($("birthYear").value, $("birthMonth").value - 1, $("birthDay").value);
		RDC.gui.disable("saveUser");
		ProfileHandler.saveBasicInfo(user, function(result){
			if(result == false){				
				PromptDialog.show("保存失败，请稍后再试！");
				RDC.gui.enable("saveUser");
			}
			else {
				$("myname").innerHTML = $("realName").value;
				$("mybirth").innerHTML = $("birthYear").value + "-" + $("birthMonth").value + "-" + $("birthDay").value;
				$("mysexdesc").innerHTML = $("sex").value;
				$("mycountry").innerHTML = $("country").value;
				$("myprovince").innerHTML = $("province").value;
				$("mylovedesc").innerHTML = $("loveType").value;
				$("mycity").innerHTML = $("city").value;	
				
				showBlock("basicInfoEdit", "basicInfoView");	
			}
		});		
	}
	
	function editContact(){
		RDC.gui.hide("contactMsg");
		showBlock("contactView", "contactEdit");
		
		$("mail").value = $("mymail").innerHTML;
		$("otherMail").value = $("myothermail").innerHTML;
		$("phone").value = $("myphone").innerHTML;
		$("MSN").value = $("mymsn").innerHTML;
		$("QQ").value = $("myqq").innerHTML;
		$("otherMail").focus();
		RDC.gui.enable("saveContact");
	}
	
	function saveContactInfo(){
		var contact = {id:$("contactId").value, aspirantId:null, otherMail:null, phone:null, MSN:null, QQ:null};
		dwr.util.getValues(contact);
		RDC.gui.disable("saveContact");
		ProfileHandler.saveContact(contact, function(result){
			if(result == null){
				PromptDialog.show("保存失败，请稍后再试！");
				RDC.gui.enable("saveContact");
			}
			else {
				$("mymail").innerHTML = $("mail").value;
				$("myothermail").innerHTML = $("otherMail").value;
				$("myphone").innerHTML = $("phone").value;
				$("mymsn").innerHTML = $("MSN").value;
				$("myqq").innerHTML = $("QQ").value;
				$("contactId").value = result;				
				
				showBlock("contactEdit", "contactView");				
			}
		});				
	}
	
	function editStudent(){
		RDC.gui.hide("studentMsg");
		showBlock("studentView", "studentEdit");
		
		$("school").value = $("myschool").innerHTML;
		var val = $("myedulevel").innerHTML;
		if(val != "")
			$("edulevel").value = val;
		val = $("myschoolfeeling").innerHTML;
		if(val != "")
			$("schoolfeeling").value = val;
		val = $("mystsartdate").innerHTML;
		if(val != "")
			$("ststartdate").value = parseInt(val);
		val = $("mystenddate").innerHTML;
		if(val != "")
			$("stenddate").value = parseInt(val);
		$("school").focus();
		RDC.gui.enable("saveStudy");
	}
	
	function saveStudyInfo(){
		var study = {id:$("studentId").value, aspirantId:null, school:null, educationLevel:null, feeling:null, startDate:null, endDate:null};
		dwr.util.getValues(study);
		study.educationLevel = $("edulevel").selectedIndex;
		study.feeling = $("schoolfeeling").selectedIndex;
		if($("ststartdate").selectedIndex > 0)
			study.startDate = new Date($("ststartdate").value, 1, 1);
		if($("stenddate").selectedIndex > 0)
			study.endDate = new Date($("stenddate").value, 1, 1);
		
		RDC.gui.disable("saveStudy");
		ProfileHandler.saveStudent(study, function(result){
			if(result == null){
				PromptDialog.show("保存失败，请稍后再试！");
				RDC.gui.enable("saveStudy");
			}
			else {
				$("myschool").innerHTML = $("school").value;
				if($("edulevel").selectedIndex > 0)
					$("myedulevel").innerHTML = $("edulevel").value;
				if($("schoolfeeling").selectedIndex > 0)
					$("myschoolfeeling").innerHTML = $("schoolfeeling").value;
				if($("ststartdate").selectedIndex)
					$("mystsartdate").innerHTML = $("ststartdate").value;
				if($("stenddate").selectedIndex)
					$("mystenddate").innerHTML = $("stenddate").value;
				$("st_sepatator").innerHTML = "~";	
				$("studentId").value = result;
				showBlock("studentEdit", "studentView");
			}
		});
	}
	
	function editBusiness(){
		RDC.gui.hide("businessMsg");
		showBlock("businessView", "businessEdit");
		
		$("jobTitle").value=$("mycareer").innerHTML;
		$("organization").value=$("myorganization").innerHTML;
		var val = $("myjobfeeling").innerHTML;
		if(val != "")
			$("jobfeeling").value = val;
		$("crstartdate").value = $("mycrstartdate").innerHTML;
		$("crenddate").value = $("mycrenddate").innerHTML;
		$("jobTitle").focus();
		RDC.gui.enable("saveCareer");
	}
	
	function saveBizInfo(){
		var career = {id:$("careerId").value, aspirantId:null, jobTitle:null, organization:null, feeling:null, startDate:null, endDate:null};
		dwr.util.getValues(career);
		career.feeling = $("jobfeeling").selectedIndex;
		if($("crstartdate").selectedIndex > 0)
			career.startDate = new Date($("crstartdate").value, 1, 1);
		if($("crenddate").selectedIndex > 0)
			career.endDate = new Date($("crenddate").value, 1, 1);
		
		RDC.gui.disable("saveCareer");
		ProfileHandler.saveCareer(career, function(result){
			if(result == null){
				PromptDialog.show("保存失败，请稍后再试！");
				RDC.gui.enable("saveCareer");
			}
			else {
				$("mycareer").innerHTML = $("jobTitle").value;
				$("myorganization").innerHTML = $("organization").value;
				if($("jobfeeling").selectedIndex > 0)
					$("myjobfeeling").innerHTML = $("jobfeeling").value;
				if($("crstartdate").selectedIndex)
					$("mycrstartdate").innerHTML = $("crstartdate").value;
				if($("crenddate").selectedIndex)
					$("mycrenddate").innerHTML = $("crenddate").value;
				$("cr_sepatator").innerHTML = "~";	
				$("careerId").value = result;
				showBlock("businessEdit", "businessView");				
			}
		});
	}

 	// status information 	 
 	function initStateDiv(){
 		showTask();
 	}
 	 
 	function showTask(){
 		if(!RDC.gui.exist("taskList")){
 			return;
 		}
 		
		if($("taskList").value != "0"){	
			RDC.gui.display("task-exec");
			var op = $("taskList").options[$("taskList").selectedIndex];
			fillInExecTable(op.value);
		}
		else {
			RDC.gui.hide("task-exec");;			
		}
		resetExec();
	}
	
	function fillInExecTable(tid){
		$("execTaskLink").href = "task.do?act=view&uid=" + user_req_id +"&id=" + tid;
		$("taskId").value = $("tid"+tid).value;
		$("taskContent").innerHTML = $("etn"+tid).innerHTML;
		$("taskStatus").innerHTML = $("ets"+tid).innerHTML;
		$("taskProgress").innerHTML = $("etp"+tid).innerHTML;
		$("taskSymptom").innerHTML = $("ety"+tid).innerHTML;
		$("proportionOfTask").value = 0;
	}
	
	function resetExec(){
		$("execContent").value = "";
		$("execDate").value = RDC.util.dateToString(new Date(), "yyyy-MM-dd");
		$("execPorp").value = 0;
		$("execTimeLength").value = 0;
		RDC.gui.enable("saveExecBtn");	
		
		if($("task-exec").style.display != "none"){
			$("execContent").focus();
		}
	}
	
	function saveExec(){
		if(!checkExecContent()||!checkExecDate()||!checkExecTimeLen()||!checkExecPorp()) {
			return false;
		}
	
		var execution = { taskId:null, content:null, executeDate:null, executeTimeLength:0, proportionOfTask:0 };
		dwr.util.getValues(execution);
		execution.executeDate = RDC.util.stringToDate($("executeDate").value, RDC.jsconst.DATE_FORMAT_yMd);
		RDC.gui.disable("saveExecBtn");
		RdcAjax.createExec(execution, function(result){
			if(typeof result.taskId !== "undefined"){
				var tid = execution.taskId;
				$("taskStatus").innerHTML = result.taskStatus;
				$("taskProgress").innerHTML = result.taskProgress+"%";
				$("taskSymptom").innerHTML = result.taskSymptom;				
				$("ets"+tid).innerHTML = result.taskStatus;				
				$("etp"+tid).innerHTML = result.taskProgress+"%";
				$("ety"+tid).innerHTML = result.taskSymptom;
				
				$("count" + tid).value = parseInt($("count" + tid).value) + 1;
				var pid = result.goalId;				
				if(pid != null){	
					$("eps" + pid).innerHTML = result.goalStatus;				
					$("epp" + pid).innerHTML = result.goalProgress+"%";
					$("epy" + pid).innerHTML = result.goalSymptom;	
				}
				PromptDialog.show("执行记录保存成功！");
				
				RDC.gui.hide('task-exec');
				$('taskList').value='0';
			}
			else {
				PromptDialog.show("执行记录保存失败，由于" + result);
			}
			RDC.gui.enable("saveExecBtn");
		});		
	}
	
	function checkExecContent(){
		var str = $("execContent").value;
		if(!RDC.util.verifyText(str, 1, 200)){
			PromptDialog.show("内容字符数在1到200之间");
			return false;
		}		
		return true;
	}
	
	function checkExecDate(){
		var df = RDC.jsconst.DATE_FORMAT_yMd;
		if(!RDC.util.isValidDate($("executeDate").value, df)){
			PromptDialog.show("执行日期的格式不正确");
			$("executeDate").focus();
			return false;
		}
		else if(RDC.util.verifyFutureDate($("executeDate").value, df)){
			PromptDialog.show("执行日期不能未来某一天");
			$("executeDate").focus();
			return false;
		}
		
		return true;
	}
	
	function checkExecPorp(){
		var str = $("execPorp").value;
		if(!isInteger(str)){
			PromptDialog.show("任务比重应为正整数");
			return false;
		}
		
		var n = parseInt(str);
		var max = 100 - parseInt($("taskProgress").innerHTML);
		if(max <= 0){
			PromptDialog.show("该任务已经完成！");
			return false;
		}
		if(n < 0 ||n > max){
			PromptDialog.show("任务比重应在1%~"+max+"%之间");
			return false;
		}
		
		return true;
	}
	
	function checkExecTimeLen(){
		var str = $("execTimeLength").value;
		if(!isInteger(str)){
			PromptDialog.show("执行时长应为正整数");
			return false;
		}
		
		var n = parseInt(str);
		if(n < 0 || n > 24){
			PromptDialog.show("执行时长应在1~24之间");
			return false;
		}
	
		return true;
	}
	
	function showGoalDetails(goalId){
		if(goalId === null || typeof goalId === "undefined") {
			window.alert("wrong input in attach Goal");
			return;
		}
		$("pd_cotent_cloned").innerHTML = $("pnm" + goalId).value;
		$("pd_execount_cloned").innerHTML = $("tcn" + goalId).value; 
		$("pd_tasklink_cloned").href = "task.do?act=all&uid=" + getUID() + "&pid=" + goalId;
		$("pd_ssd_cloned").innerHTML = $("pssd" + goalId).value;
		$("pd_sed_cloned").innerHTML = $("psed" + goalId).value;
		$("pd_rsd_cloned").innerHTML = $("prsd" + goalId).value;
		$("pd_red_cloned").innerHTML = $("pred" + goalId).value;
		if(RDC.util.exist("pd_addtask_cloned")) {
			$("pd_addtask_cloned").onclick = function(){
				window.location.href = "task.do?act=create&pid=" + goalId;
			};
		}
	}
	
	function showTaskDetails(taskId){
		if(taskId === null || typeof taskId === "undefined") {
			window.alert("wrong input in attach Task");
			return;
		}
		
		$("td_goal_cloned").href = "goal.do?act=view&uid=" + getUID() +"&id=" + $("goalId" + taskId).value;
		$("td_goal_cloned").innerHTML = $("goalName" + taskId).value;
		$("td_proportion_cloned").innerHTML = $("tprop" + taskId).value;
		$("td_rank_cloned").innerHTML = $("trank" + taskId).value;;
		$("td_execlink_cloned").href = "exec.do?act=all&uid=" + getUID() + "&pid=" + taskId;
		$("td_execount_cloned").innerHTML = $("count" + taskId).value;
		$("td_newexec_cloned").innerHTML = $("lastest" + taskId).value;
		$("td_ssd_cloned").innerHTML = $("tssd" + taskId).value;
		$("td_sed_cloned").innerHTML = $("tsed" + taskId).value;
		$("td_rsd_cloned").innerHTML = $("trsd" + taskId).value;
		$("td_red_cloned").innerHTML = $("tred" + taskId).value;
		$("td_cotent_cloned").innerHTML = $("tcnt" + taskId).value;
		if(RDC.util.exist("td_addexec_cloned")) {
			$("td_addexec_cloned").onclick = function(){
				$("taskList").value = taskId;
				showTask();
			};
		}
	}
	
	// achievement information
	function initScoreDiv(){		
		var sid = getScoreId();
		if(isEmpty(sid) == false) {
			if(cmptExists("cct" + sid) == false){		
				PromptDialog.show("您要查看的记录不存在，可能已被删除");		
				// window.location.href = "/roadmap/score.do?uid="+$("user_id").value;
			}
			else {
				$("cct" + sid).style.color = "#C20101";
			}
		}
		
		resetScoreWithoutFocus();
	}
		
	function showSBtns(trid){	
		// trid's prefix is "sctrid"
		RDC.gui.lighten(trid);
		var sid = trid.substring(6);
		RDC.gui.display("edit" + sid);
		RDC.gui.display("delt" + sid);
	}
	
	function hideSBtns(trid){
		RDC.gui.goOut(trid);
		var sid = trid.substring(6);
		RDC.gui.hide("edit" + sid);
		RDC.gui.hide("delt" + sid);
	}
	
	function editScore(elemid){
		var sid = elemid.substring(4);		
		$("id").value = sid;
		$("aspirantId").value = $("asp"+sid).innerHTML;
		$("happenDate").value = $("hdt"+sid).innerHTML;
		$("scoreContent").value = $("cct"+sid).innerHTML;
		$("createdTime").innerHTML = $("ctd"+sid).value;
		$("updatedTime").innerHTML = $("utd"+sid).value;
		
		RDC.gui.disable("happenDate");
		RDC.gui.enable("saveBtn");
		$("scoreContent").focus();
	}
		
	function deltScore(elemid){
		var uid = getUID();
		var sid = elemid.substring(4);
		var score = {};
		score.id = sid;	
		score.content = $("cct"+sid).innerHTML;
		RDC.gui.disable("delt" + sid);	
		ScoreHandler.deltScore(uid, score, function(result){
			if(result == false){
				PromptDialog.show("删除失败！");
				RDC.gui.enable("delt" + sid);
			}
			else {				
				var row = $("sctrid" + sid);
				$("scoretable").deleteRow(row.rowIndex);
				var num = parseInt(dwr.util.getValue("scoreNum"));
				if(num > 0)
					dwr.util.setValue("scoreNum", num - 1);
				if(sid == $("id").value){
					resetScore();
				}
				PromptDialog.show("删除成功！");
			}
		});		
	}
	
	function resetScore(){
		resetScoreWithoutFocus();
		$("scoreContent").focus();
	}
	
	function resetScoreWithoutFocus(){
		if(!RDC.gui.exist("id")){
			return;
		}
		
		$("id").value = "";
		$("aspirantId").value = "";		
		$("scoreContent").value = "";
		var dt = new Date();
		$("happenDate").value = RDC.util.dateToString(dt, "yyyy-MM-dd");		
		$("createdTime").innerHTML = RDC.util.dateToString(dt, "yyyy-MM-dd HH:mm:ss");
		$("updatedTime").innerHTML = $("createdTime").innerHTML;	
		
		RDC.gui.enable("saveBtn");	
		RDC.gui.enable("happenDate");
		$("happenDate").style.color = "black";	
	}
	
	function saveScore(){
		if(!checkHpnDate() || !checkContent())
			return;
		
		var uid = getUID();
		var score = {id:null,aspirantId:null,content:null,happenDate:null,createdTime:null,updatedTime:null};
		dwr.util.getValues(score);
		score.content = $("scoreContent").value;
		score.happenDate = RDC.util.stringToDate($("happenDate").value, "yyyy-MM-dd");
		score.createdTime = RDC.util.stringToDate($("createdTime").innerHTML, "yyyy-MM-dd HH:mm:ss");		
		score.updatedTime = new Date();
		
		RDC.gui.disable("saveBtn");
		ScoreHandler.saveScore(uid, score, function(result){
			if(result == null){
				PromptDialog.show("保存失败！");
				RDC.gui.enable("saveBtn");
			}
			else {				
				var sid = result.id;
				var node = dwr.util.byId("sctrid" + sid);
				if(node == null){
					dwr.util.cloneNode("sctrid", {idSuffix:sid});
					var num = parseInt(dwr.util.getValue("scoreNum")) + 1;
					dwr.util.setValue("scoreNum", num);
				}
				dwr.util.setValue("hdt" + sid, $("happenDate").value);
				dwr.util.setValue("cct" + sid, $("scoreContent").value);
				dwr.util.setValue("ctd" + sid, $("createdTime").innerHTML);
				var utd = RDC.util.dateToString(score.updatedTime, "yyyy-MM-dd HH:mm:ss");
				dwr.util.setValue("updatedTime", utd);
				dwr.util.setValue("utd" + sid, utd);
				dwr.util.setValue("asp" + sid, $("aspirantId").value);				
				dwr.util.byId("sctrid" + sid).style.display = "";
				PromptDialog.show("保存成功！");
				resetScoreWithoutFocus();
			}
		});		
	}
	
	function checkHpnDate(){
		var df = RDC.jsconst.DATE_FORMAT_yMd;
		if(!RDC.util.isValidDate($("happenDate").value, df)){
			PromptDialog.show("执行日期的格式不正确");
			$("happenDate").focus();
			return false;
		}
		else if(RDC.util.verifyFutureDate($("happenDate").value, df)){
			PromptDialog.show("收获日期不能是未来某一天");
			$("happenDate").focus();
			return false;
		}
		return true;
	}
		
	function checkContent(){
		var str = $("scoreContent").value;
		if(!RDC.util.verifyText(str, 1, 200)){
			PromptDialog.show("内容字符数在1到200之间");
			return false;
		}		
		return true;
	}
